<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="css/public.css" type="text/css" rel="stylesheet"/>
    <script src="js/jquery-1.7.2.js"></script>
    <script src="js/mapConfig.js"></script>
    <script src="objClass/objQuery.js"></script>
    <script src="objClass/objFunction.js"></script>
    <script src="objClass/objGeoStyle.js"></script>
    <script src="objClass/objBubble.js"></script>
    <script src="objClass/objGeometry.js"></script>
    <script src="objClass/objInfowindow.js"></script>
    <script src="js/mapThemePopo.js"></script>
    <script src="js/mapPublicFunction.js"></script>
    <script src="js/mapShowLocation.js"></script>

    <style>
        .esriPopup .titleButton.maximize {
            display: none;
        }
/****************楼层插件*************************/
        #btnFloor {
          height: 320px;
          width: 32px;
          margin-top: 1px;
          position: absolute;
          top: 200px;
          left: 65px;
          z-index: 101;
          display: none;
        }

        #img_bag{
          width: 32px;
          background: #F2F2F2;
          margin: 0 auto;
          text-align: center;
          padding: 2px 0;
          z-index: 101;
        }
        #img_bag > a {
          margin-left: 1px;
        }
        #floorDIV{
          width: 24px;
          background: #F2F2F2;
          overflow: hidden;
          margin: 0 auto;
          max-height: 150px;
        }
        #floorDIV ul {
          margin: 0;
          padding: 0;
          list-style: none;
        }

        #floorDIV li {
          padding: 0;
          width: 24px;
          height: 24px;
          overflow: hidden;
          margin: 5px 0;
          display: block;
        }

        #floorDIV li a{
          display: block;
          background: #fff;
          font-size: 12px;
          color: #000;
          line-height: 25px;
          text-align: center;
          text-decoration: none;
        }
        #floorDIV li a:hover {
          background: #99addf;
          color: #ff6600;
        }
        #floorDIV li a.activeFloor{
          background: rgb(153, 173, 223);
          color: rgb(255, 102, 0);
        }
/****************楼层插件END*************************/

        .contentPane > div {
          overflow: auto;
        }
        #imgDiv,#content {
          float: left;
        }
        .imgStyle{
          width:210px;
          height:140px;
          margin-right:15px;
        }

        .tablestyle{
          width: 270px;
        }
        .tablestyle tr {
          height: 28px;
          line-height: 28px;
        }
        .esriPopup .actionsPane .zoomTo {
            display: none;
        }
        .esriPopup .titleButton.maximize {
            display: none;
        }
        .esriPopup .titleButton.close {
            top: 16px !important;
            right: 16px !important;
            height: 12px !important;
            width: 12px !important;
            background: url(img/ico_close.gif) no-repeat scroll center center transparent;
            background-position: center !important;
        }
        .esriPopup .pointer,
        .esriPopup .pointer.top,
        .esriPopup .outerPointer {
            background-color: #fff;
        }
        .esriPopup .titlePane {
          background-color: #fff !important;
          padding: 6px 6px 2px 6px;
        }

        .esriPopup .titlePane .title {
            background: #f1f1f1;
            padding-left: 8px;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
            font-size: 14px;
            height: 32px;
            line-height: 32px;
            color:#333;
        }
        .esriPopup .titlePane .title a{
          text-decoration: none;
        }
    </style>
</head>
<body style="height:100%; width:100%" onload="initPage()" class="tundra">
<div id="btnFloor" style="display: none;">
  <div id="img_bag">
    <a href="javascript:void(0)" onmousedown="moveTop()"><img class="img" width="24" src="img/arrowtopbottom1.png" border="0"></a>
    <div id="floorDIV">
      <ul id="floorUL">

      </ul>
    </div>
    <a href="javascript:void(0)" onmousedown="moveBottom()"><img class="img" width="24" src="img/arrowtopbottom2.png" border="0"></a>
  </div>
</div>
<div id="map" style="position:absolute; left:0; top:0; width:100%; height:100%;">
</div>
<!--<div style="position:absolute; right:1%; top:1%;">-->
    <!--<label>切换城市：</label>-->
    <!--<select name="jumpCity" id="jumpCity" onchange="jumpCity();">-->
        <!--<option value="1101">北京市</option>-->
        <!--<option value="3101">大连市</option>-->
        <!--<option value="4401">丹东市</option>-->
        <!--<option value="4403">珠海市</option>-->
    <!--</select>-->
<!--</div>-->

<div class="mapbtnbox">
  <input id="location" type="hidden" name="location" value="定位" onclick="position(event)"/>
  <div id="mapbtntext">
    影像图
  </div>
</div>
<script type="text/javascript">
  var map;
  var baseLayer;
  var imgLayer;//影像底图
  var showType;//记录当前显示类型（影像底图、矢量底图）

  var landLayer;    //土地层
  var indoorLayer;  //室内结构
  var houseLayer;   //室内单元
  var buildPointLayer;   //楼栋图层
  var graphicLayerDataArray = [];
  var graphicLayerPolygon;              //面图层
  var graphicLayerPolygonGray;          //面图层，带有边界，无填充色
  var graphicLayerPolygonLabel;         //面图层标注
  var graphicLayerPoint;                // 点图层，用来存放小区，楼栋
  var highlightLayerXQAnalysis;          //小区，周边租金，缓冲分析
  var graphicLayerPolygonsArray = [];   //记录面要素层存放数据的id.
  var _extent = [];                     // 存储查询的小区点矩形范围

  var provinceName = "";
  var cityName = "大连市";
  var districtName = "";
  var parentArea_ID = "";
  var Area_ID = "";
  var CityAreaID = [];

  var ghighlightProvince = [];      // 省
  var ghighlightCity = [];          // 市
  var ghighlightDistrict = [];      // 区 全局变量

  var coord_city = [];
  var coord_district = [];

  var objData;
  var searchType;   // 查询类型

  var gArea_ID;    // 全局变量，存放点击的高亮物块AREA_ID

  //加载ArcgisAPI样式
  objFunction.loadCss(config.urlAPI + "/dijit/themes/claro/claro.css");
  objFunction.loadCss(config.urlAPI + "/esri/css/esri.css");
  //加载ArcgisAPI脚本
  objFunction.loadJs(config.urlAPI + "/init.js");

  function initPage() {
    dojo.require("esri.map");
    dojo.require("esri.geometry.geodesicUtils");
    dojo.require("esri.tasks.GeometryService");
    dojo.require("esri.tasks.AreasAndLengthsParameters");
    dojo.require("esri.SpatialReference");
    dojo.require("esri.tasks.query");
    dojo.require("dojo.parser");
    dojo.require("esri.Color");
    dojo.require("esri.symbols.Font");
    dojo.require("esri.symbols.TextSymbol");
    dojo.require("esri.tasks.geometry");
    dojo.require("esri.symbols.SimpleFillSymbol");
    dojo.require("esri.toolbars.draw");
    dojo.require("esri.tasks.IdentifyTask");
    dojo.require("esri.tasks.IdentifyParameters");
    dojo.require("esri.units");

    //初始化地图div
    initMap();
    showType = configShowLayerType.Vector;
    baseLayer = new esri.layers.ArcGISTiledMapServiceLayer(config.urlBaseLayer);
    //添加矢量图到map
    map.addLayer(baseLayer);

    imgLayer = new esri.layers.ArcGISTiledMapServiceLayer(config.urlImgLayer);
    map.addLayer(imgLayer);
    imgLayer.hide();

    //初始化基类
    initObj();
    //向地图添加临时层
    addTempLayer();
    //定位到指定范围
    setExtent();
    // 绑定地图事件
    BindEvent();
  }
  function initObj() {
    objQuery.init(config.wkid, map);
    objGeometry.init(config.wkid);
    objInfowindow.init(map);
  }

  //初始化地图div
  function initMap() {

    map = new esri.Map(
      'map'
      , {
        logo: false,
        slider: true,
        minZoom: config.minZoom,
        sliderStyle: "large"
      });
  }

  function setExtent(e) {
    //定位到指定范围
    var extent = new esri.geometry.Extent({
      "xmin": config.xmin, "ymin": config.ymin, "xmax": config.xmax,
      "ymax": config.ymax, "spatialReference": {
        "wkid": config.wkid
      }
    });
    if (e == "北京市") { //北京
      extent = new esri.geometry.Extent({
        "xmin": config.xmin_BJ, "ymin": config.ymin_BJ, "xmax": config.xmax_BJ,
        "ymax": config.ymax_BJ, "spatialReference": {
          "wkid": config.wkid
        }
      });
    }
    else if (e == "丹东市") { // 丹东
      extent = new esri.geometry.Extent({
        "xmin": config.xmin_DD, "ymin": config.ymin_DD, "xmax": config.xmax_DD,
        "ymax": config.ymax_DD, "spatialReference": {
          "wkid": config.wkid
        }
      });
    }
    else if (e == "珠海市") { //珠海
      extent = new esri.geometry.Extent({
        "xmin": config.xmin_ZH, "ymin": config.ymin_ZH, "xmax": config.xmax_ZH,
        "ymax": config.ymax_ZH, "spatialReference": {
          "wkid": config.wkid
        }
      });
    }
    else if (e == "大连市") { // 大连
      extent = new esri.geometry.Extent({
        "xmin": config.xmin_DL, "ymin": config.ymin_DL, "xmax": config.xmax_DL,
        "ymax": config.ymax_DL, "spatialReference": {
          "wkid": config.wkid
        }
      });
    }
    else if (e == "成都市") { // 成都
      extent = new esri.geometry.Extent({
        "xmin": config.xmin_CD, "ymin": config.ymin_CD, "xmax": config.xmax_CD,
        "ymax": config.ymax_CD, "spatialReference": {
          "wkid": config.wkid
        }
      });
    }
    //map.setExtent(extent);
    map.centerAndZoom(extent.getCenter(), config.initZoom);
  }

  //矢量影像切换方法
  function reloadMap(type) {
    if (type == showType) return;

    if (showType == configShowLayerType.Img) {
      //basemap.show();
      showType = configShowLayerType.Vector;
    }
    else if (showType == configShowLayerType.Vector) {
      //imgLayer.show();
      showType = configShowLayerType.Img;
    }
    else {
      return;
    }

    if (showType == configShowLayerType.Img) {
      imgLayer.show();
      baseLayer.hide();
    }
    if (showType == configShowLayerType.Vector) {
      baseLayer.show();
      imgLayer.hide();
    }
  }


  //添加临时层
  function addTempLayer() {
//    Layer1 = new esri.layers.GraphicsLayer();
//    map.addLayer(Layer1);
//    Layer1Lable = new esri.layers.GraphicsLayer();
//    map.addLayer(Layer1Lable);

    landLayer = new esri.layers.GraphicsLayer();
    map.addLayer(landLayer);
    graphicLayerPolygonGray = new esri.layers.GraphicsLayer();
    map.addLayer(graphicLayerPolygonGray);

    graphicLayerPolygon = new esri.layers.GraphicsLayer();
    map.addLayer(graphicLayerPolygon);

    graphicLayerPoint = new esri.layers.GraphicsLayer();
    map.addLayer(graphicLayerPoint);

    graphicLayerPolygonLabel = new esri.layers.GraphicsLayer();
    map.addLayer(graphicLayerPolygonLabel);

    highlightLayerXQAnalysis = new esri.layers.GraphicsLayer();
    map.addLayer(highlightLayerXQAnalysis);

    indoorLayer = new esri.layers.GraphicsLayer();//加载临时图层
    map.addLayer(indoorLayer);

    houseLayer = new esri.layers.GraphicsLayer();
    map.addLayer(houseLayer);

    buildPointLayer = new esri.layers.GraphicsLayer();
    map.addLayer(buildPointLayer);
  }
  //地图事件绑定
  function BindEvent() {
    dojo.connect(map, "onUpdateEnd", function (e, l, le, lod) {
      ExtentChanged();
    });
    dojo.connect(graphicLayerPolygon, "onClick", function (e) {
      var msg = {};
      // 省
      if (map.getLevel() <= config.showProvinceLevel) {
        provinceName = e.graphic.attributes.NAME;
        cityName = "";
        districtName = "";
        msg.province = provinceName;
        msg.city = cityName;
        msg.district = districtName;
        sendMessage(msg);
      }
      // 市
      if (map.getLevel() >= config.showCityLevelBegin && map.getLevel() <= config.showCityLevelEnd) {
        var parent_area = e.graphic.attributes.PARENT_AREA;
        cityName = e.graphic.attributes.NAME;
        districtName = "";
        queryProvince(parent_area);
        setTimeout(function () {   // 延迟1秒，保证数据的一致性
          msg.province = provinceName;
          msg.city = cityName;
          msg.district = districtName;
          sendMessage(msg);
        }, 1000);
      }
      // 区
      if (map.getLevel() >= config.showDistrictLevelBegin && map.getLevel() <= config.showDistrictLevelEnd) {
        var parent_area = e.graphic.attributes.PARENT_AREA;
        districtName = e.graphic.attributes.NAME;
        // 查询市
        queryCity(parent_area);

        setTimeout(function () {    // 延迟1秒，保证数据的一致性
          msg.city = cityName;
          msg.district = districtName;
          msg.province = provinceName;
          sendMessage(msg);
        }, 1000);
      }

    });
    dojo.connect(graphicLayerPolygon, "onMouseOver", function (e) {
      if (map.getLevel() >= 8 && map.getLevel() <= 10) {
        cityName = e.graphic.attributes.NAME;
      }
      if (map.getLevel() >= 11 && map.getLevel() <= 14) {
        Area_ID = e.graphic.attributes.AREA_ID;
      }
    });

    dojo.connect(graphicLayerPolygon, "onDblClick", function (e) {
      // 点击缩放
      if (e.graphic.attributes && e.graphic.attributes.layerID) {
        if (e.graphic.attributes.layerID == "provincePolygon") {
          // 查询点击的市级坐标
          console.log(objData);
          var areaId = e.graphic.attributes.AREA_ID;
          coord_city = [];
          // 遍历objData全局json
          for (var k = 0; k < objData.data.queryAreaByParams.length; k++) {
            if (objData.data.queryAreaByParams[k].parentArea == areaId) {
              var ext = [];
              ext.x = objData.data.queryAreaByParams[k].longitude;
              ext.y = objData.data.queryAreaByParams[k].latitude;
              coord_city.push(ext);
              break;
            }
          }
          var pt = createPoint(parseFloat(coord_city[0].x), parseFloat(coord_city[0].y));
          map.centerAndZoom(pt, config.zoomCity);
        }
        else if (e.graphic.attributes.layerID == "cityPolygon") {
          coord_district = [];
          var areaId = e.graphic.attributes.AREA_ID;
          for (var k = 0; k < objData.data.queryAreaByParams.length; k++) {
            if (objData.data.queryAreaByParams[k].parentArea == areaId) {
              var ext = [];
              ext.x = objData.data.queryAreaByParams[k].longitude;
              ext.y = objData.data.queryAreaByParams[k].latitude;
              coord_district.push(ext);
            }
          }
          var pt2 = createPoint(parseFloat(coord_district[coord_district.length-1].x), parseFloat(coord_district[coord_district.length-1].y));
          map.centerAndZoom(pt2, config.zoomDistrict);
        }
        else if (e.graphic.attributes.layerID == "districtPolygon") {
          map.centerAndZoom(e.graphic.geometry.getExtent().getCenter(), config.showMapGJXQ);
        }
      }
    });

    dojo.connect(graphicLayerPoint, "onClick", function (e) {
      var content = "";

      // 缩放到小区级别，点击小区点，发送消息
      var msg = {};
      msg.type = "clickedXQ";
      msg.communityId = e.graphic.attributes.ADDRESS_ID;
      msg.communityName = e.graphic.attributes.LABEL;
      msg.address = e.graphic.attributes.ADDR_FULL_NAME;
      sendMessage(msg);
    });

    dojo.connect(graphicLayerPoint, "onMouseMove", function (e) {
      showInfoWindows2(map, e.graphic.geometry, "小区信息", e.graphic.attributes.LABEL, 200, 100);
    });
    dojo.connect(graphicLayerPoint, "onMouseOut", function (e) {
      map.infoWindow.hide();
    });

    dojo.connect(highlightLayerXQAnalysis, "onMouseMove", function (e) {
      var content = "";
      content += "小区名称：" + e.graphic.attributes.communityName + "<br/>";
      showInfoWindows2(map, e.graphic.geometry, "小区信息", content, 200, 100);
    });
    dojo.connect(highlightLayerXQAnalysis, "onMouseOut", function (e) {
      map.infoWindow.hide();
    });

    dojo.connect(highlightLayerXQAnalysis, "onClick", function (e) {
      var pt = e.graphic.geometry;
      map.setZoom(17);
      map.centerAt(pt);
      var msg = {};
      msg.type = "clickedXQ";
      msg.communityId = e.graphic.attributes.addressId;
      msg.communityName = e.graphic.attributes.communityName;
      msg.address = e.graphic.attributes.address;
      sendMessage(msg);
    });

    dojo.connect(graphicLayerPolygonGray, "onClick", function (e) {
      if (e.graphic.attributes && e.graphic.attributes.layerID) {
        if (e.graphic.attributes.layerID == "LDR") {
          $('#floorUL li').remove();
          map.centerAndZoom(e.mapPoint, 19);
          var floor_total = e.graphic.attributes.FLOOR_TOTAL;     //总层数
          var ground_total = e.graphic.attributes.GROUND_TOTAL;     //地上层数
          var under = Number(floor_total) - Number(ground_total);
          if(floor_total != null && Number(floor_total) > 0){
            if(ground_total && Number(ground_total) > 0){
              for(var i=Number(ground_total);i > 0;i--){
                var floorIndex = "F"+i;
                $('#floorUL').append("<li id='liF"+i+"'><a href='javascript:void(0)' onclick='getFloorShow("+e.graphic.attributes.BUILD_ID+",\""+floorIndex+"\",this)'>F"+i+"</a></li>");
              }
            }else{
              console.log("地上层数获取失败...");
            }
          }
          if(under && under > 0){
            for(var j=1;j<=under;j++){
              var floorIndex = "B"+j;
              $('#floorUL').append("<li id='liB"+j+"'><a href='javascript:void(0)' onclick='getFloorShow("+e.graphic.attributes.BUILD_ID+",\""+floorIndex+"\",this)'>B"+j+"</a></li>");
            }
          }else{
            console.log("地下层数获取失败...");
          }
          //通过点击的楼栋面展示内部结构
          if(Number(floor_total) > 0){
            getFloorShow(e.graphic.attributes.BUILD_ID,"F1");

            $('#btnFloor').css('display','block');
            moveMostBottom();
          }else{console.log("该楼栋未采集内部信息"); }
        }
      }
    });
    //室内
    dojo.connect(houseLayer, "onClick", function (e){
      if (e.graphic.attributes && e.graphic.attributes.layerID) {
        if (e.graphic.attributes.layerID == "HU") {
          var graphic = e.graphic;
          var attr = e.graphic.attributes;
          var title = "",content = "";
          console.log(attr);
          var house_id = attr.HOUSE_ID == null || attr.HOUSE_ID == undefined || attr.HOUSE_ID == "" ?"": attr.HOUSE_ID;
          var house_num = attr.HOUSE_NUM == null || attr.HOUSE_NUM == undefined || attr.HOUSE_NUM == "" ?"": attr.HOUSE_NUM;
          var file_path = attr.FILE_PATH == null || attr.FILE_PATH == undefined || attr.FILE_PATH == "" ?"": attr.FILE_PATH;
          var house_address = attr.HOUSE_ADDRESS == null || attr.HOUSE_ADDRESS == undefined || attr.HOUSE_ADDRESS == "" ?"": attr.HOUSE_ADDRESS;
          var build_floor = attr.BUILD_FLOOR == null || attr.BUILD_FLOOR == undefined || attr.BUILD_FLOOR == "" ?"": attr.BUILD_FLOOR;
          var house_state = attr.HOUSE_STATE == null || attr.HOUSE_STATE == undefined || attr.HOUSE_STATE == "" ?"": attr.HOUSE_STATE;
          if(house_state == 1){house_state = "自用"}else if(house_state == 2){house_state = "出租"};
          var housesyarea = attr.HOUSESYAREA == null || attr.HOUSESYAREA == undefined || attr.HOUSESYAREA == "" ? 0: attr.HOUSESYAREA;

          content += "<div>";
          //图片DIV
          if(file_path == ""){
            content += "  <div id='imgDiv'><img class='imgStyle' src='img/nophoto.png'></div>";
          }else{
            content += "  <div id='imgDiv'><img class='imgStyle' src='"+config.imageURL+file_path+"'></div>";
          }
          //表格DIV
          content += "  <div id='content'>";
          content += "    <table class='tablestyle'>";
          content += "      <tr><td>所属单位：" + house_address + "</td></tr>";
          content += "      <tr><td>楼层：" + build_floor + "</td></tr>";
          content += "      <tr><td>房号：" + house_num + "</td></tr>";
          content += "      <tr><td>状态：" + house_state + "</td></tr>";
          content += "      <tr><td>面积：" + housesyarea + "m²</td></tr>";
          content += "    </table>";
          content += "  </div>";
          content +="</div>";

          title = house_num ;
          title += "&emsp;<a href='javascript:void(0);' onclick='queryHouseDetail("+house_id+")'>详情</a>";
          title += "&emsp;<a href='javascript:void(0);' onclick='editHouseDetail("+house_id+")'>编辑</a>";
          showInfoWindows(map, graphic.geometry, title, content, 530, 250);
        }
      }
    });

    dojo.connect(buildPointLayer, "onClick", function (e) {
        console.log("ld:",e.graphic.attributes);
        if (e.graphic.attributes && e.graphic.attributes.layerID) {
            if(e.graphic.attributes.layerID = "LDR"){
                queryLDDetail(e.graphic);
            }
        }
    });
  }

  function ExtentChanged() {
//    dojo.connect(map, "onZoomEnd", function (extent, zoomFactor, pt, level) {
//      //graphicLayerPoint.clear();
//    });
    console.log(map.getLevel());
    // 省级
    if (map.getLevel() <= 7) {
      showProvincePolygons();
      graphicLayerPolygon.show();
      graphicLayerPolygonLabel.show();
      highlightLayerXQAnalysis.hide();
      graphicLayerPolygonGray.hide();
    }
    else if (map.getLevel() >= 8 && map.getLevel() <= 10) {// 市级
//      showCityPolygonsGray();
      showCityPolygons();
      showCityPolygonsGray();
      graphicLayerPolygon.show();
      graphicLayerPolygonLabel.show();
      highlightLayerXQAnalysis.hide();
      graphicLayerPolygonGray.show();
    }
    else if (map.getLevel() >= 11 && map.getLevel() <= 14) {// 区级
      showDistrictPolygons();
      graphicLayerPolygon.show();
      graphicLayerPolygonLabel.show();
      highlightLayerXQAnalysis.show();                      //小区显示
      graphicLayerPolygonGray.hide();
    }
    else if (map.getLevel() >= 15  && map.getLevel() <= 16) {
      highlightLayerXQAnalysis.show();                      //小区显示
      graphicLayerPolygon.hide();
      graphicLayerPolygonLabel.hide();
      graphicLayerPoint.clear();
    }
    //显示楼栋面
    if (map.getLevel() > 16) {
      //graphicLayerPolygonGray.hide();
      highlightLayerXQAnalysis.hide();
      graphicLayerPolygon.hide();
      graphicLayerPolygonLabel.hide();
      graphicLayerPolygonGray.show();

      queryLDR();
      queryLandR();
    }else{
      graphicLayerDataArray = [];
      graphicLayerPolygonGray.clear();
      graphicLayerPoint.clear();
      buildPointLayer.clear();
      landLayer.clear();
    }
    if(map.getLevel() < 19){
      houseLayer.clear();
      indoorLayer.clear();
      graphicLayerPolygonGray.show();
      $('#btnFloor').css('display','none');
    }
  }

  function jumpCity() {
    setExtent($("#jumpCity").val());

  }

  // 清除地图和数组
  function clearGraphic() {
    graphicLayerPointsArray = [];
//            graphicLayerPolygonsArray = [];
    graphicLayerLablesArray = [];
    graphicLayerPolygon.clear();
    graphicLayerPolygonLabel.clear();
    graphicLayerPoint.clear();
    highlightLayerXQAnalysis.clear();
  }

function getFloorShow(build_id,floor_id,that){
    $('#floorUL li a').removeClass("activeFloor");
    $(that).addClass("activeFloor");
    console.log("楼：",build_id,"楼层:",floor_id);
    indoorLayer.clear();
    houseLayer.clear();

    var SQL = " 1=1 and BUILD_ID ='"+build_id+"' and FLOOR_ID ='"+floor_id+"'";
    QueryBySQL(config.urlIndoor+config.urlIndoor_unit,SQL,(function(res){
        console.log("内部结构",res);
        for(var i=0;i<res.features.length;i++){
          var graphic = res.features[i];
          var symbol = getPolygonStyleByDoubleColor("#5E5E5E","#FF0000");
          graphic.attributes.layerID = "FLOOR";

          var graf = new esri.Graphic(graphic.geometry, symbol, graphic.attributes);
          indoorLayer.add(graf);
        }
      }),(function(){console.log("查询内部结构失败...");}));
    //内部商户
    var HouseSQL = " 1=1 and BUILD_ID ="+build_id+" and BUILD_FLOOR ='"+floor_id+"'";
    QueryBySQL(config.urlIndoor+config.urlIndoor_room,HouseSQL,(function(res){
        console.log("商户",res);
        for(var i=0;i<res.features.length;i++){
          var graphic = res.features[i];
          var picURL = "img/circle.png";
          if(graphic.attributes.HOUSE_ACTION)
            picURL = "img/building/"+graphic.attributes.HOUSE_ACTION+".png";
          var symbol = new esri.symbol.PictureMarkerSymbol({
            "url": picURL,"type": "esriPMS"
          });
          symbol.setHeight(20);
          symbol.setWidth(20);
          graphic.attributes.layerID = "HU";

          var graf = new esri.Graphic(graphic.geometry, symbol, graphic.attributes);
          houseLayer.add(graf);
        }
      }),(function(){console.log("查询内部商户失败...");}));
  }

//根据楼栋id查询楼栋详细信息
function queryLDDetail(graphic){
  var buildId = graphic.attributes.BUILD_ID;
  var postUrl = ajaxUrl.queryLDDetail;
  var data = {"buildingCode":buildId};
  $.ajax({
    url: postUrl,
    type: "POST",
    data: data,
    async: false,
    /*beforeSend: function (xhr) {
      xhr.setRequestHeader("token",sessionStorage.getItem('tokenData'));
    },*/
    success: function (res) {
      //var result = eval('(' + res + ')');
      console.log("楼栋详细信息：",res);
      var content="";
      var transfer_unit = res["transfer_unit"] == null || res["transfer_unit"] == undefined || res["transfer_unit"] == "" ? "": res["transfer_unit"];
      var building_name = res["building_name"] == null || res["building_name"] == undefined || res["building_name"] == "" ? "": res["building_name"];
      var use = res["use"] == null || res["use"] == undefined || res["use"] == "" ? "": res["use"];
      var building_area = res["building_area"] == null || res["building_area"] == undefined || res["building_area"] == "" ? "": res["building_area"];
      var filePath = res["filePath"] == null || res["filePath"] == undefined || res["filePath"] == "" ? "": res["filePath"];
      if(filePath){filePath = config.imageURL + filePath}
      var location = res["location"] == null || res["location"] == undefined || res["location"] == "" ? "": res["location"];
      content += "<div>";
      //图片DIV
      if(filePath == ""){
        content += "  <div id='imgDiv'><img class='imgStyle' src='img/nophoto.png'></div>";
      }else{
        content += "  <div id='imgDiv'><img class='imgStyle' src='"+filePath+"'></div>";
      }
      //表格DIV
      content += "  <div id='content'>";
      content += "    <table class='tablestyle'>";
      content += "      <tr><td>划转单位：" + transfer_unit + "</td></tr>";
      content += "      <tr><td>楼栋名称：" + building_name + "</td></tr>";
      content += "      <tr><td>类别：" + use + "</td></tr>";
      content += "      <tr><td>建筑面积：" + building_area + "m²</td></tr>";
      content += "      <tr><td>地址：" + location + "</td></tr>";
      content += "    </table>";
      content += "  </div>";
      content +="</div>";

      title = building_name;
      title += "&emsp;<a href='javascript:void(0);' onclick='queryBuildDetail("+buildId+")'>详情</a>";
      title += "&emsp;<a href='javascript:void(0);' onclick='editBuildDetail("+buildId+")'>编辑</a>";
      showInfoWindows(map, graphic.geometry, title, content, 530, 250);

    }
  });
}
</script>
<script type="text/javascript">
  function queryBuildDetail(num_id){
    var win = window.open("/fe/assetMap/buildingDetails?buildingCode="+num_id,'_blank');
    win.focus();
  }

  function editBuildDetail(num_id){
    var win = window.open("/fe/assetMap/buildingEdit?buildingCode="+num_id,'_blank');
    win.focus();
  }

  function queryHouseDetail(num_id){
    var win = window.open("/fe/assetMap/houseDetails?houseCode="+num_id,'_blank');
    win.focus();
  }

  function editHouseDetail(num_id){
    var win = window.open("/fe/assetMap/houseEdit?houseCode="+num_id,'_blank');
    win.focus();
  }

  function moveTop() {
    var $wrapper = $("#floorDIV");
    $wrapper.animate({scrollTop: $wrapper.scrollTop() - $wrapper.height() + 5}, 250);
  }
  function moveBottom() {
    var $wrapper = $("#floorDIV");

    console.log($("#floorDIV").scrollTop(),$("#floorDIV").height(), $("#floorUL").height())

    $wrapper.animate({scrollTop: $wrapper.scrollTop() + $wrapper.height() - 5}, 250);

  }
  function moveMostBottom() {
    var $wrapper = $("#floorDIV");
    var $wrapperUl = $("#floorUL");
    $wrapper.animate({scrollTop: $("#floorUL").height() - $("#floorDIV").height() + 10}, 0);
  }

  function bindEvent(element, eventName, eventHandler) {
    if (element.addEventListener) {
      element.addEventListener(eventName, eventHandler, false);
    } else if (element.attachEvent) {
      element.attachEvent('on' + eventName, eventHandler);
    }
  }

  bindEvent(window, 'message', function (e) {
    var obj = JSON.parse(e.data);
    objData = JSON.parse(e.data);
    console.log("receive param：", obj);
    var filter = obj.type;
    searchType = obj.searchType;
    var content = "";
    var ext = [];
    var ext_coord = [];

    highlightCity = [];
    highlightDistrict = [];

    if (filter == "filter") {
      // 初始状态加载高亮物块
    	if (obj.data.queryAreaByParams) {
//        ghighlightProvince = [];
//        ghighlightCity = [];
//        ghighlightDistrict = [];
        for (var k = 0; k < obj.data.queryAreaByParams.length; k++) {
          if (obj.data.queryAreaByParams[k].areaLevel == "1") {         // 省
            ghighlightProvince.push(obj.data.queryAreaByParams[k].areaId);
          }
          else if (obj.data.queryAreaByParams[k].areaLevel == "2") {    // 市
            ghighlightCity.push(obj.data.queryAreaByParams[k].areaId);
          }
          else if (obj.data.queryAreaByParams[k].areaLevel == "3") {     // 区
            ghighlightDistrict.push(obj.data.queryAreaByParams[k].areaId);
            ext_coord.x = obj.data.queryAreaByParams[k].longitude;
            ext_coord.y = obj.data.queryAreaByParams[k].latitude;
            coord_district.push(ext_coord);
          }
        }
      }

      // 加载搜索条件
      if (obj.data.screenSelect) {
    	    console.log("查询结果：",obj.data);
        ext = [];
        highlightLayerXQAnalysis.clear();
        for (var i = 0; i < obj.data.screenSelect.length; i++) {
          var src = "img/point_4.png";
          var communityId = obj.data.screenSelect[i].communityId;
          var communityName = obj.data.screenSelect[i].communityName;
          var city = obj.data.screenSelect[i].city;
          var address = obj.data.screenSelect[i].address;
          var xCoord = obj.data.screenSelect[i].xCoord;
          var yCoord = obj.data.screenSelect[i].yCoord;

          var content = communityName;

          var attribute = [];
          attribute.addressId = communityId;      // addressId
          attribute.address = address;
          attribute.communityName = communityName;

          attribute.x = xCoord;                        // x坐标
          attribute.y = yCoord;                        // y坐标
          attribute.layerID = "XQ";                    // 图层ID
          addPopo(highlightLayerXQAnalysis, xCoord, yCoord, src, 20, 20, attribute, content, "9pt", 10, 5, 0);
          var attr = [];
          attr.x = parseFloat(xCoord);
          attr.y = parseFloat(yCoord);
          ext.push(attr);
        }
        //highlightLayerXQAnalysis.hide();
        //var temp = objGeometry.createExtentByPoints(ext);
        //map.setExtent(temp);
//        map.centerAndZoom(temp.getCenter(), config.zoomXQ);
      }
    }

    // 查询模式
//    graphicLayerPoint.clear();
    if (searchType == "3") {    // 查询小区
      if (obj.data) {
        var x = obj.data.xCoord;
        var y = obj.data.yCoord;
        var communityId = obj.data.communityId;
        var communityName = obj.data.communityName;
        var buildCount = obj.data.buildCount;
        var houseCount = obj.data.houseCount;
        var address = obj.data.address;
        content = "";

        var src = "img/point_4.png";
        var attribute = [];
        attribute.addressId = communityId;      // addressId
        attribute.address = address;
        attribute.communityName = communityName;
        attribute.buildCount = buildCount;
        attribute.houseCount = houseCount;

        attribute.x = x;                        // x坐标
        attribute.y = y;                        // y坐标
        attribute.layerID = "XQ";               // 图层ID
        highlightLayerXQAnalysis.clear();
        addPopo(highlightLayerXQAnalysis, x, y, src, 25, 25, attribute, content, "9pt", 10, 5, 0);
        var pt = createPoint(parseFloat(x), parseFloat(y));
        map.centerAndZoom(pt, config.showMapGJXQ);
//        ext = [];
//        var attr = [];
//        attr.x = parseFloat(x);
//        attr.y = parseFloat(y);
//        ext.push(attr);
      }
    }
    else if (searchType == "1") {      // 划转单位
      if (obj.data.length > 0) {
        highlightLayerXQAnalysis.clear();
        graphicLayerPoint.clear();
        var item = [];
        var community = [];
        ext = [];
        for (var i = 0; i < obj.data.length; i++) {
          item = obj.data[i];
          for (var k = 0, len = item.communityList.length; k < len; k++) {
            community = item.communityList[k];

            var communityId = community.communityId;
            var communityName = community.communityName;
            var address = community.address;
            var city = community.city;
            var houseCount = community.houseCount;
            var buildCount = community.buildCount;
            var x = community.xCoord;
            var y = community.yCoord;
            content = "";

            var addr = [];
            addr.city = city;
            addr.addressId = communityId;
            CityAreaID.push(addr);

            var src = "img/point_4.png";
            var attribute = [];
            attribute.addressId = communityId;      // addressId
            attribute.address = address;
            attribute.communityName = communityName;
            attribute.buildCount = buildCount;
            attribute.houseCount = houseCount;

            attribute.x = x;                        // x坐标
            attribute.y = y;                        // y坐标
            attribute.layerID = "XQ";               // 图层ID
            if ((x != "-") && (y != "-")) {
              addPopo(highlightLayerXQAnalysis, x, y, src, 25, 25, attribute, content, "9pt", 10, 5, 0);

              var attr = [];
              attr.x = parseFloat(x);
              attr.y = parseFloat(y);
              ext.push(attr);
            }
          }   // end for second
        }  // end for  first
        if (ext.length > 0) {
          var temp = objGeometry.createExtentByPoints(ext);
          if (ext.length == 1) {
            map.centerAndZoom(temp.getCenter(), config.showMapGJXQ);
          } else {
            map.setExtent(temp);
          }
        }
      }
    }
    else if (searchType == "2") {     //项目
      if (obj.data.length > 0) {
        highlightLayerXQAnalysis.clear();
        console.log("项目：", obj.data);
        var item = [];
        var community = [];
        ext = [];
        for (var i = 0; i < obj.data.length; i++) {
          item = obj.data;
          //for (var k = 0; k < obj.length; k++) {
          community = item[i];

          var communityId = community.communityId;
          var communityName = community.communityName;
          var address = community.address;
          var city = community.city;
          var houseCount = community.houseCount;
          var buildCount = community.buildCount;
          var x = community.xCoord;
          var y = community.yCoord;
          content = "";

          var src = "img/point_4.png";
          var attribute = [];
          attribute.addressId = communityId;      // addressId
          attribute.address = address;
          attribute.communityName = communityName;
          attribute.buildCount = buildCount;
          attribute.houseCount = houseCount;
          attribute.x = x;                        // x坐标
          attribute.y = y;                        // y坐标
          attribute.layerID = "XQ";               // 图层ID
          if ((x != "-") && (y != "-")) {
            addPopo(highlightLayerXQAnalysis, x, y, src, 25, 25, attribute, content, "9pt", 10, 5, 0);

            var attr = [];
            attr.x = parseFloat(x);
            attr.y = parseFloat(y);
            ext.push(attr);
          }
          //}   // end for second
        }  // end for  first
        if (ext.length > 0) {
          var temp = objGeometry.createExtentByPoints(ext);
          if (ext.length == 1) {
            map.centerAndZoom(temp.getCenter(), config.showMapGJXQ);
          } else {
            map.setExtent(temp);
          }
        }
      }
    }
    ExtentChanged();
  });

  //向父级发送消息
  var sendMessage = function (msg) {
    window.parent.postMessage(msg, '*');
  };

  function position(e){
    var xx = getRootPath();
    alert(xx);
    var pt = new esri.geometry.Point(12946238.691,4862056.333,map.spatialReference);
    //var pt = new esri.geometry.Point(12940634.765732,4906039.923011,map.spatialReference);

//    var pt = new esri.geometry.Point(12937143.18285,4869269.787450001,map.spatialReference);
    map.centerAndZoom(pt);
    e.stopPropagation();
  }
</script>
</body>
</html>



